#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <unistd.h>
#define MAXSIZE 10
#define max(a,b) (((a)>(b))?(a):(b))
int main(int argc, char *argv[]){
	/*code here*/
	int i, j;
	int n=10;
	int s[MAXSIZE][MAXSIZE]={0};
	int pi[MAXSIZE]={8,7,4,2,5,1,9,3,10,6};
	for(j = 0; j < pi[0]-1; j++ )
		s[0][j] = 0;
	for(j = pi[0]-1; j < n; j++ )
		s[0][j] = 1;
	for(i = 1; i < n; i++ ){
		for(j = 0; j < n; j++ ){
			if( j < pi[i]-1)
				s[i][j] = s[i-1][j];
			else
				s[i][j] = max(s[i-1][j],s[i-1][pi[i]]+1);
		}
	}
	printf("%d\n", s[n-1][n-1]);
}
